package com.itydl.loveview.view;

import android.animation.TypeEvaluator;
import android.graphics.PointF;

/**
 * 作者：${Howard} on 2018/2/12 09:42
 *
 * @version 1.0
 *          说明：自定义估值器（转换器），把进度值转为数值。可以在AnimatorUpdateListener
 *          方法中拿到当前的值
 */
public class BezerEvaluator implements TypeEvaluator<PointF> {

    private PointF mPointP1;
    private PointF mPointP2;

    //通过构造方法赋值
    public BezerEvaluator(PointF pointP1,PointF pointP2){
        this.mPointP1 = pointP1;
        this.mPointP2 = pointP2;
    }

    @Override
    public PointF evaluate(float fraction, PointF pointP0, PointF pointP3) {
        PointF pointF = new PointF();
        float t = fraction;//由插值器计算出来的

        pointF.x = pointP0.x*(1-t)*(1-t)*(1-t)
                + mPointP1.x*3*t*(1-t)*(1-t)
                + mPointP2.x*3*(1-t)*t*t
                + pointP3.x*t*t*t;

        pointF.y = pointP0.y*(1-t)*(1-t)*(1-t)
                + mPointP1.y*3*t*(1-t)*(1-t)
                + mPointP2.y*3*(1-t)*t*t
                + pointP3.y*t*t*t;

        return pointF;
    }
}
